package org.linlinjava.litemall.admin.web;

import org.linlinjava.litemall.admin.service.AdminMemberRuleService;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LitemallMemberRule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/admin/memberRule")
public class AdminMemberRuleController {
    @Autowired
    private AdminMemberRuleService memberRuleService;

    /**
     * 新增会员规则
     * @param memberRule
     * @return
     */
    @PostMapping("/create")
    public Object createRule(@RequestBody LitemallMemberRule memberRule) {
        return memberRuleService.createMemberRule(memberRule);
    }

    /**
     * 修改会员规则
     * @param memberRule
     * @return
     */
    @PostMapping("/update")
    public Object updateRule(@RequestBody LitemallMemberRule memberRule) {
        return ResponseUtil.ok(memberRuleService.updateMemberRule(memberRule));
    }

    /**
     * 删除会员规则
     * @param memberRuleId
     * @return
     */
    @PostMapping("/delete/{id}")
    public Object deleteRule(@PathVariable("id") Integer memberRuleId) {
        return memberRuleService.deleteMemberRule(memberRuleId);
    }

    /**
     * 查询租书规则列表
     * @return
     */
    @GetMapping("/list")
    public Object listRules() {
        return memberRuleService.listMemberRules();
    }

    /**
     * 获取一个详情
     * @param memberRuleId
     * @return
     */
    @GetMapping("/findOne")
    public Object findRule(@RequestParam Integer memberRuleId) {
        return memberRuleService.findOne(memberRuleId);
    }
}
